﻿namespace FaceService.Infrastructure.Helpper;

public class FaceHellper : IFace
{
    public async Task<List<float>> GetExtract(string image)
    {
        using HttpClient client = new HttpClient();
        using Stream stream = await client.GetStreamAsync(image);
        using var bitmap = SKBitmap.Decode(stream);
        using FaceDetector faceDetector = new FaceDetector();
        using FaceLandmarker faceMark = new FaceLandmarker();
        using FaceRecognizer faceRecognizer = new FaceRecognizer();

        var info = faceDetector.Detect(bitmap).First();
        var point = await faceMark.MarkAsync(bitmap, info);
        var result = await faceRecognizer.ExtractAsync(bitmap, point);
        return result.ToList();
    }

    public float Compare(List<float> p0, List<float> p1)
    {
        using FaceRecognizer faceRecognizer = new FaceRecognizer();
        float result = faceRecognizer.Compare(p0.ToArray(), p1.ToArray());

        return result;
    }
}
